package com.zzptc.easyshop.dao;

import com.zzptc.easyshop.db.IDB;
import com.zzptc.easyshop.db.MysqlDB;
import com.zzptc.easyshop.factory.DaoFactoryImp;
import com.zzptc.easyshop.vo.Good;
import com.zzptc.easyshop.vo.Users;
import com.zzptc.easyshop.vo.VO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProductDao implements  IDAO{

    @Override
    public boolean insert(VO vo)throws SQLException{
        return false;
    }

    /**
     *
     * @return
     * @throws SQLException
     */

    @Override
    public List getAll() throws SQLException {
        List list=new ArrayList();
        //获取数据库连接
        IDB db=new MysqlDB();
        Connection conn=db.getConnnection();
        //获取工具
        PreparedStatement ps=conn.prepareStatement("select * from easy_product_category");
        //操作数据库
        ResultSet rs=ps.executeQuery();
        while (rs.next()){
            Good goog=new Good();
            goog.getEpc_id(rs.getInt("1"));
            goog.getEpc_name(rs.getString("2"));
            goog.getEpc_paren_id(rs.getInt("3"));
            list.add(goog);
        }
        return list;
    }

    @Override
    public boolean deleteByID(VO vo) throws SQLException {
        return false;
    }

    @Override
    public boolean update(VO vo) throws SQLException {
        return false;
    }

    @Override
    public VO getByID(VO vo) throws SQLException {
        return null;
    }

    @Override
    public boolean login(Users user) {
        return false;
    }

    public static void main(String[] args) {
        try {
            ProductDao dao=(ProductDao) DaoFactoryImp.getlnstance().createDAO("productdao");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
